/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pricecomparison.websitereader.projectorquest;

import java.io.IOException;
import javax.swing.JLabel;
import jxl.write.WriteException;
import pricecomparison.PriceComparisonView;

/**
 *
 * @author Jim Simon
 */
public class PQ_HomePageReader {
    public String URL = "http://www.projectorquest.com/projector-lamps.html";
    
    public void beginSearch(String page, boolean newSheet, JLabel l) throws jxl.write.WriteException, java.net.MalformedURLException, java.io.IOException {
        // Format Page
        page = URL + "/" + page;
        page = page.replace(".html", "").trim();
        page += ".html";

        try {
            if (newSheet)
                PriceComparisonView.excelWriter.newSheet(PriceComparisonView.excelWriter.MFER_PROJECTORQUEST);
            PQ_ItemListReader group = new PQ_ItemListReader(page);
            String nextPage = group.getNextPage();
            
            // Do first page
            group.beginSearch(l);
            
            // Do rest of pages
            while (nextPage != "") {   
                group = new PQ_ItemListReader(nextPage);
                nextPage = group.getNextPage();
                group.beginSearch(l);
            }
        } catch (jxl.write.WriteException e) {
            throw e;
        } catch (java.net.MalformedURLException e) {
            throw e;
        } catch (java.io.IOException e) {
            throw e;
        }
    }
}
